package com.ruoyi.finance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finance.domain.ERate;
import com.ruoyi.finance.service.IERateService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 汇率管理Controller
 *
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/rate")
public class ERateController extends BaseController
{
    @Autowired
    private IERateService eRateService;

    /**
     * 查询汇率管理列表
     */
    @RequiresPermissions("finance:rate:list")
    @GetMapping("/list")
    public TableDataInfo list(ERate eRate)
    {
        startPage();
        List<ERate> list = eRateService.selectERateList(eRate);
        return getDataTable(list);
    }

    /**
     * 导出汇率管理列表
     */
    @RequiresPermissions("finance:rate:export")
    @Log(title = "汇率管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ERate eRate)
    {
        List<ERate> list = eRateService.selectERateList(eRate);
        ExcelUtil<ERate> util = new ExcelUtil<ERate>(ERate.class);
        util.exportExcel(response, list, "汇率管理数据");
    }

    /**
     * 获取汇率管理详细信息
     */
    @RequiresPermissions("finance:rate:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(eRateService.selectERateById(id));
    }

    /**
     * 新增汇率管理
     */
    @RequiresPermissions("finance:rate:add")
    @Log(title = "汇率管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ERate eRate)
    {
        return toAjax(eRateService.insertERate(eRate));
    }

    /**
     * 修改汇率管理
     */
    @RequiresPermissions("finance:rate:edit")
    @Log(title = "汇率管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ERate eRate)
    {
        return toAjax(eRateService.updateERate(eRate));
    }

    /**
     * 删除汇率管理
     */
    @RequiresPermissions("finance:rate:remove")
    @Log(title = "汇率管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(eRateService.deleteERateByIds(ids));
    }
    /**
     * 根据id查询汇率详情列表
     */
    @RequiresPermissions("finance:rate:getRateList")
    @GetMapping("/getRateList/{id}")
    public TableDataInfo getRateList(@PathVariable("id") Integer id)
    {
        startPage();
        List<ERate> list = eRateService.getRateList(id);
        return getDataTable(list);
    }
}
